using System;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Data.OleDb;
using Oracle.DataAccess.Client;
using MySql.Data.MySqlClient;
 
namespace DataAccess
{
  public sealed class DBManagerFactory
  {
    private DBManagerFactory(){}
    public static IDbConnection GetConnection(DataProvider providerType)
    {
      IDbConnection iDbConnection = null;
      switch (providerType)
      {
		  case DataProvider.MySQL:
			  iDbConnection = new MySqlConnection();
			  break;
        case DataProvider.SqlServer:
          iDbConnection = new SqlConnection();
          break;
        case DataProvider.Oracle:
          iDbConnection = new OracleConnection();
          break;
        default:
          return null;
      }
      return iDbConnection;
    }
 
    public static IDbCommand GetCommand(DataProvider providerType)
    {
      switch (providerType)
      {
		  case DataProvider.MySQL:
			  return new MySqlCommand();
        case DataProvider.SqlServer:
          return new SqlCommand();
       
        case DataProvider.Oracle:
          return new OracleCommand();
        default:
          return null;
      }
    }
 
    public static IDbDataAdapter GetDataAdapter(DataProvider providerType)
    {
      switch (providerType)
      {
		  case DataProvider.MySQL:
			  return new MySqlDataAdapter();
        case DataProvider.SqlServer:
          return new SqlDataAdapter();
       
        case DataProvider.Oracle:
          return new OracleDataAdapter();
        default:
          return null;
      }
    }
 
    public static IDbTransaction GetTransaction(DataProvider providerType)
    {
      IDbConnection iDbConnection =GetConnection(providerType);
      IDbTransaction iDbTransaction =iDbConnection.BeginTransaction();
      return iDbTransaction;
    }

	  public static IDataParameter GetParameter(DataProvider providerType)
	  {
		  IDataParameter iDataParameter = null;
		  switch (providerType)
		  {
			  case DataProvider.MySQL:
				  iDataParameter = new MySqlParameter();
				  break;
			  case DataProvider.SqlServer:
				  iDataParameter = new SqlParameter();
				  break;
			
			  case DataProvider.Oracle:
				  iDataParameter = new OracleParameter();
				  break;

		  }
		  return iDataParameter;
	  }
 
    public static IDbDataParameter[] GetParameters(DataProvider providerType,int paramsCount)
    {
      IDbDataParameter[]idbParams = new IDbDataParameter[paramsCount];
 
      switch (providerType)
      {
		  case DataProvider.MySQL:
			  for (int i = 0; i < paramsCount; ++i)
			  {
				  idbParams[i] = new MySqlParameter();
			  }
			  break;
        case DataProvider.SqlServer:
          for (int i = 0; i < paramsCount;++i)
          {
            idbParams[i] = new SqlParameter();
          }
          break;
      
        case DataProvider.Oracle:
			for (int i = 0; i < paramsCount; ++i)
          {
            idbParams[i] = new OracleParameter();
          }
          break;
        default:
          idbParams = null;
          break;
      }
      return idbParams;
    }
  }
}
